﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Data.SqlClient;


namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        String date = "";
        String note = "";
        public Form1()
        {
            InitializeComponent();
            groupBox1.Hide();
            button1.Hide();
            textBox1.Hide();
            richTextBox1.Hide();
            label2.Hide();
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            textBox1.Text = monthCalendar1.SelectionStart.ToString();
            richTextBox1.Show();
            label2.Show();
            monthCalendar1.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            groupBox1.Show();
            button1.Show();
            textBox1.Show();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            date = textBox1.Text;
            note = richTextBox1.Text;

            if (date != "" && note != "")
            {
                saveNote();
            }
            else
            {
                MessageBox.Show("Niet alle velden zijn ingevuld!");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }
     
        public void saveNote()
        {


            MySqlConnection grabConnection = new MySqlConnection("Server=instance8003.db.xeround.com;Port=6006;Database=GrabCollab;Uid=cookicom0;Pwd=pizzahut91;");
            MySqlCommand agenda = new MySqlCommand("INSERT INTO agenda (date, note, projectID)" + "VALUES (@date, @note, 1)", grabConnection);
            agenda.Parameters.Add(new MySqlParameter("date", date));
            agenda.Parameters.Add(new MySqlParameter("note", note));

            try
            {
                grabConnection.Open();
                agenda.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show("Sql error detected!");
            }
            finally
            {
                grabConnection.Close();
                MessageBox.Show("Agendapunt succesvol opgeslagen!");
            }
        }

    }
}
